package com.hqd.ch03.v50.boot;

import com.hqd.ch03.v50.beans.factory.config.BeanDefinition;

@FunctionalInterface
public interface LazyInitializationExcludeFilter {

    /**
     * Factory method that creates a filter for the given bean types.
     *
     * @param types the filtered types
     * @return a new filter instance
     */
    static LazyInitializationExcludeFilter forBeanTypes(Class<?>... types) {
        return (beanName, beanDefinition, beanType) -> {
            for (Class<?> type : types) {
                if (type.isAssignableFrom(beanType)) {
                    return true;
                }
            }
            return false;
        };
    }

    /**
     * Returns {@code true} if the specified bean definition should be excluded from
     * having {@code lazy-init} automatically set.
     *
     * @param beanName       the bean name
     * @param beanDefinition the bean definition
     * @param beanType       the bean type
     * @return {@code true} if {@code lazy-init} should not be automatically set
     */
    boolean isExcluded(String beanName, BeanDefinition beanDefinition, Class<?> beanType);

}
